<div class="row"> <h3 class="page-header">分类管理</h3></div>
<div class="row">
    <div class="panel panel-default">
        <div class="panel-body">
        	<label><a class="btn btn-primary addText"  data-id='{$list.id}'>添加分类</a></label>
            <div class="table-responsive">
                <table class="table table-striped table-bordered table-hover">
                    <thead>
                        <tr>
                            <th width="60">序号</th>
                            <th>分类名称</th>
                            <th>分类别名</th>
                            <th>链接地址</th>
                            <th width="75">排序</th>
                            <th width="75">状态</th>
                            <th width="120">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                     <empty name="list">
                            <tr><td colspan="7" align="center">暂无信息</td></tr>
                        </empty>
                    	<volist name="list" id="list_news">
                            <tr>
                                <td>{$i}</td>
                                <td style="padding-left:{:18 * $list_news['num']}px;">|-{$list_news.name}</td>
                                <td>{$list_news.subname|default='无'}</td>
                                <td><empty name='list_news.link'>无<else/><a href="{$list_news.link}" target="_blank">点击查看</a></empty></td>
                                <td><input class="setSort" type="text" size="2" data-url="{:U('Classify/setSort?id='.$list_news['id'])}" value="{$list_news.sort}"></td>
                                <td><button class='btn <eq name="list_news.status" value="1">btn-primary<else />btn-default</eq> btn-sm setStatus' type="button" data-url='{:U("Classify/setStatus?id=".$list_news["id"])}' data-status="{$list_news.status}"><eq name="list_news.status" value='1'>启用<else />禁用</eq></button></td>
                                <td>
                             	    <a class="btn-sm btn btn-default editText"  data-id='{$list_news.id}'>修改</a>
                             	    <button data-url='{:U("Classify/del?id=".$list_news["id"])}' class="btn-sm btn btn-default delBtn" type="button">删除</button>
                                </td>
                            </tr>
                        </volist>
                    </tbody>
                </table>
            </div>
            {$page}
        </div>
    </div>
</div>

<div id="myModal" class="modal fade in" style="display: none;">
    <div class="modal-dialog">
        <div class="modal-content">
            <form action="{:U('Classify/add')}" id="myform" class="form-horizontal">
                <div class="modal-header">
                    <button data-dismiss="modal" class="close" type="button">×</button>
                    <h4 class="modal-title">分类管理</h4>
                </div>
                <div class="modal-body">
                <div class="form-group">
                    <label class="col-sm-3 control-label">上级分类：</label>
                    <div class="col-sm-4 input-group">
                        <select class="form-control" name="pid">
                            <option value="0">无上级</option>
                            <volist name='list' id='list'>
                                <option value="{$list.id}" <eq name='info.pid' value='$list["id"]'>selected</eq>>{:str_pad('', $list['num'] * 18 - 18, '&nbsp;&nbsp;&nbsp;')}|-{$list.name}</option>
                            </volist>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">分类名称：<span class="c-red">*</span></label>
                    <div class="col-sm-4 input-group">
                        <input class="form-control required" name="name">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">分类别名：</label>
                    <div class="col-sm-4 input-group">
                        <input class="form-control" name="subname" maxlength="100">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">图片：</label>
                    <div class="col-sm-4 input-group">
                        <div class="uploadify-div"></div>
                        <button type="button" class="upload" id="upload">选择图片</button>

                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">链接地址：</label>
                    <div class="col-sm-4 input-group">
                        <input class="form-control url" name="link">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">排序：</label>
                    <div class="col-sm-4 input-group">
                        <input class="form-control digits" name="set_sort" value="100">
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 control-label">状态：</label>
                   <div class="col-sm-4 input-group">
                        <label class="radio-inline">
                            <input type="radio" value="1" name="set_status" checked>启用
                        </label>
                        <label class="radio-inline">
                            <input type="radio" value="0" name="set_status">禁用<BR>
                        </label>
                    </div>
                </div>
                </div>
                <div class="modal-footer">
                      <button data-dismiss="modal" class=" btn btn-default" type="button">关闭</button>
                        <button class="btn btn-primary" type="submit">保存</button> 
                    </div>     
                <input type='hidden' name='id' value='{$info.id}'>
            </form>
        </div>
    </div>
</div>

<script>
$(function(){
    $('.addText').click(function(){
        $('#myform')[0].reset();
        $('.uploadify-div').html("");
        $('#myModal').modal('show');
    });
    $('.editText').click(function(){
        $('#myform')[0].reset();
        var id = $(this).data('id'); waiting();
        $.get('{:U("Classify/edit")}', {id: id}, function(data){
            complete();
             if(data.status == 1){
                var _get_info = data.info;
                $('#myform select[name="pid"]').val(_get_info.pid);
                $('#myform input[name="id"]').val(_get_info.id);
                $('#myform input[name="name"]').val(_get_info.name);
                $('#myform input[name="subname"]').val(_get_info.subname);
                $('#myform input[name="link"]').val(_get_info.link);
                $('#myform input[name="set_sort"]').val(_get_info.sort);
                $("#myform :radio[name=set_status][value='"+_get_info.status+"']").attr("checked",true)
                var div = $('.uploadify-div');
                if(_get_info.pic.length > 0){
                    //有图片
                    var html = '<li>';
                    html += "<img src='"+_get_info.pic+"' />";
                    html += "<input type='hidden' name='pic' value='"+_get_info.pic+"' /><span style='color:blue;cursor:pointer;' class='uploadifyDel'>删除</span></li>";
                    div.html(html);
                }else{
                    div.html("");
                }
                $('#myform').attr('action', '{:U("Classify/edit")}');
                $('#myModal').modal('show');
            }else{
                 showInfo(data.info);
                 setTimeout('_form_defult_callback()', 1600);
            }
        });
    });



})
</script>